package com.swd.order.service;

import com.swd.order.mapper.OrderItemMapper;
import com.swd.order.model.Foods;
import com.swd.order.model.OrderItem;
import com.swd.order.model.OrderItemExample;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
@Slf4j
public class OrderItemService {

    @Autowired
    private OrderItemMapper orderItemMapper;
    @Autowired
    private FoodsService foodsService;

    public boolean orderItemSave(List<Foods> foods,Integer orderId,Boolean extraMeal){
        OrderItemExample orderItemExample = new OrderItemExample();

        List<OrderItem> orderItemList = foods.stream().map(item ->
                new OrderItem(orderId, item.getId(), item.getNum(),extraMeal)).collect(Collectors.toList());
        int i = orderItemMapper.insertList(orderItemList);
        if (i!=orderItemList.size()){
            return false;
        }
        return true;
    }



}
